<?php

class Service_Model_DbTable_Loan extends Custom_Db_Table_Abstract
{

    public $_name = 'vt_loans';

    public function getLoans($customerId, $fields = '*')
    {
        $objCustomer = new Service_Model_DbTable_Customer();

        try
		{
           $select = $this->select()
							->setIntegrityCheck(false)
							->from(array('master' => $this->_name), $fields)
							->join(array('customer' => $objCustomer->_name), 'customer.id = master.customer_id')
                            ->where("master.customer_id = ? ", $customerId);

           if ($this->_roleId != User_Model_DbTable_Role::ADMIN_USER)
              $select->where("customer.bank_id = ? ", $this->_bankId);

           return $this->_applyPaginator($select)->toArray();
           
        }catch(Exception $e){
            $this->setError($e->getMessage());
			return false;
        }
    }
}